<html>
<head>
<title>附近的人</title>
<include file="SPGPub:header" />

<script src="{cms>:STATICS}/jQuery/jquery-1.8.3.min.js"></script>

<style type="text/css">
.bottom_div{
background-color: #fff;
margin: 0 -15px;
padding: 10px;
}

.bottom_div input{
width: 80%;
}

.bottom_div .btn{
display: inline-block;
width: 18%;
}
</style>
</head>

<body>
	
	<header class="titlebar">
		<a href="{cms>:U('Spgclub/index')}">返回</a>
		<h1>聊天</h1>
	</header>

	<div class="chat_container">
		
		<div id="chat_box" class="chatbox" style="height: 380px;overflow-y:auto; ">
			<div class="chatbox_my">
				<img src="{cms>:STATICS}/u20.png">
				<P>AAAAAAAAAAAA AAAAAAAAAAAAAAAAAA AAAAAAAAAAAAA AAAAAAAAAA AAAAAAAAAAAAAA AAAAAAAAAAA AAAAAAAAAAA AAAAAAAAAAA AAAAAAAAAAAAAAAAAA AAAAAAA AAAAAAAAAA</P>
			</div>
			
			<div class="chatbox_other">
				<img src="{cms>:STATICS}/u20.png">
				<P>及时了解对方律师阿斯利康结果及时了解对方律师阿斯利康结果及时了解对方律师阿斯</P>
			</div>
		</div>
		
		<div class="bottom_div">
			<input type="text" id="msg" name="msg">
			<button onclick="chat();" class="btn">发送</button>
		</div>
	</div>
	
	<include file="SPGPub:footer" />	
	
</body>

<script type="text/javascript">

$(function(){
	getNewMsg();
	//setInterval("getNewMsg()",5000);
});


function chat(){
	var msg = $('#msg').val();
	
	var mypicurl = "{cms>:STATICS}/u20.png";
	
	if(msg.length > 0){
		var mymsgdiv = $('<div class="chatbox_my">' + 
				'<img src="'+ mypicurl +'">' + 
				'<P>'+ msg +'</P>' + 
				'</div>');
		
		var c_box = $('#chat_box');
		c_box.append(mymsgdiv);
		$('#chat_box').scrollTop(c_box[0].scrollHeight);
		
		var surl = "{cms>:U('Wap/Spgclub/sendNewMsg')}";
		
		data = new FormData();
	    data.append("msg", msg);
	    
	    $.ajax({
			data:data,
			dataType:'json',
			type:"POST",
			url:surl,
			cache: false,
	        contentType: false,
	        processData: false,
	        success: function(data) {
	        	
	        	if(data.success != true){
	        		alert('上传失败:' + data.info);
				}
	        }
		});
		
		$('#msg').val('');
	}
}

function getNewMsg(){
	var url = "{cms>:U('Wap/Spgclub/getNewMsg')}";
	
	$.getJSON(url,function(data){
		
		if(data == "false"){ return;}
		
		for(var i = 0; i<data.length;i++){
			var d = data[i];
			
			var msgdiv = $('<div class="chatbox_other">' + 
					'<img src="'+ d.img +'">' + 
					'<P>'+ d.msg +'</P>' + 
					'</div>');
			
			var c_box = $('#chat_box');
			c_box.append(msgdiv);
			$('#chat_box').scrollTop(c_box[0].scrollHeight);
		}
	});
}

</script>

</html>
